<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>ENC进销存管理系统</title>
    <meta name="renderer" content="webkit">
    <meta name="_token" content="{{ csrf_token() }}"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/admin/css/font.css">
    <link rel="stylesheet" href="/static/admin/css/login.css">
    <link rel="stylesheet" href="/static/admin/css/xadmin.css">

    <script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/admin/js/xadmin.js"></script>
</head>

<body class="login-bg">

<div class="login layui-anim layui-anim-up">
    <div class="message"><h2>ENC进销存管理系统</h2></div>
    <form class="layui-form">
        <input name="userName" placeholder="用户名" type="text" lay-verify="username" class="layui-input th15">
        <input name="userPassword" placeholder="密码" type="password" lay-verify="password" class="layui-input th15">
        <button class="layui-btn th15" lay-filter="login" lay-submit="" style="width:100%;background-color:#2c6cbd">登录
        </button>
    </form>
</div>

<script>
    layui.use(['form', 'layer', 'jquery'], function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        //自定义验证规则
        form.verify({
            username: function (value) {
                if (value.length < 3) {
                    return '昵称至少得3个字符啊';
                }
            }
            , password: [/(.+){3,12}$/, '密码必须3到12位']
        });
        //监听提交
        form.on('submit(login)', function (data) {
            //发异步，把数据提交给php
            $.ajax({
                type: 'POST',
                url: '/admin/login',
                data: data.field,
                dataType: 'json',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {
                    if (data.code == 1) {
                        location.href = '/admin';
                    } else {
                        layer.alert(data.msg)
                    }
                },
                error: function (xhr, type) {
                    alert('Ajax error!')
                }
            });
            return false;
        });
    });
</script>
</body>

</html>
